package com.nsccjn.aoh.eslog.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger2配置文件
 * http://localhost:8080/swagger-ui.html    原路径
 * http://localhost:8080/doc.html    换肤之后的路径
 */
@Configuration
@EnableSwagger2
public class Swagger2 {


    //api接口包扫描路径
    public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.nsccjn.aoh.eslog.controller";

    public static final String VERSION = "1.0.0";

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)   // 指定API类型为SWAGGER_2
                .apiInfo(apiInfo())                      // 定义API文档汇总信息
                .select()
                .apis(RequestHandlerSelectors
                        .basePackage(SWAGGER_SCAN_BASE_PACKAGE))   // 指定controller包，用于生成api的controller包
                .paths(PathSelectors.any())              // 可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("ESLog服务平台") //设置文档的标题
                .contact(new Contact("天天吃货",
                        "http://192.168.186.142:8080/index",
                        ""))
                .description("ESLog服务平台 API 接口文档") // 设置文档的描述
                .version(VERSION) // 设置文档的版本信息-> 1.0.0 Version information
                .termsOfServiceUrl("http://www.baidu.com") // 设置文档的License信息->1.3 License information
                .build();
    }
}